package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    IPermissionService permissionService;

    @RequestMapping("view")
    public String view() {
        return "permission";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo) {
        return permissionService.query(qo);
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public List<Permission> selectAll() {
        return permissionService.selectAll();
    }
    @RequestMapping("reload")
    @ResponseBody
    public JsonResult reload() {
        try {
            permissionService.reload();
            return JsonResult.success("");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.mark("加载失败");
        }
    }

}
